home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Development Tools / Unsupported Tools / SignatureToApp 1.1 / Example MPW Tool / Launch.c next >
Encoding:
C/C++ Source or Header  |  1991-06-07  |  2.7 KB  |  105 lines  |  [TEXT/MPS ]

  1. ////
  2. ////    Launch.c                Test tool for SignatureToApp.
  3. ////
  4. ////    By Jens Alfke            ©1991 Apple Computer, Inc. All rights reserved.
  5. ////
  6.  
  7. ////    This is a little demo tool that shows how to call SignatureToApp.
  8. ////    Usage:
  9. ////        Launch ( [-proc] [-file] [-launch] signature )*
  10. ////    where signature is a 4-character application signature.
  11. ////
  12. ////    Default behavior is to launch or bring to the front the application with that signature.
  13. ////    Leading flags will modify this:
  14. ////        -proc means only to look for a running process with that signature.
  15. ////        -file means to find a running process or a file, but not launch it
  16. ////        -launch (the default) means to find a running process or find and launch an app. 
  17. ////    You can list more than one signature. Each flag modifies the behavior for following
  18. ////    signatures until another flag is found.
  19.  
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25. #include <Errors.h>
  26. #include <Memory.h>
  27.  
  28. #include "SignatureToApp.h"
  29.  
  30. main( int argc, char *argv[] )
  31. {
  32.     Boolean foundSignature = false;
  33.     short arg;
  34.     Sig2App_Mode mode = Sig2App_LaunchApplication;
  35.     char *argstr;
  36.     OSType sig;
  37.     ProcessSerialNumber psn;
  38.     FSSpec file;
  39.     Boolean launched;
  40.     OSErr err;
  41.     long len;
  42.     
  43.     if( argc<=1 ) {
  44.         puts("Launch: Finds and/or launches application with given signature");
  45.         return 1;
  46.     }
  47.     
  48.     for( arg=1; arg<argc; arg++ ) {
  49.         argstr = argv[arg];
  50.         
  51.         // Interpret a flag:
  52.         
  53.         if( argstr[0] == '-' ) {
  54.             if( strcmp(argstr,"-proc")==0 )
  55.                 mode = Sig2App_FindProcess;
  56.             else if( strcmp(argstr,"-file")==0 )
  57.                 mode = Sig2App_FindApplication;
  58.             else if( strcmp(argstr,"-launch")==0 )
  59.                 mode = Sig2App_LaunchApplication;
  60.             else {
  61.                 fprintf(stderr,"Launch: Unknown flag “%s”\n",argstr);
  62.                 return 1;
  63.             }
  64.             continue;
  65.         } else {
  66.         
  67.             // Interpret anything else as an application signature:
  68.             
  69.             foundSignature = true;
  70.             sig = '    ';
  71.             len = strlen(argstr);
  72.             if( len>4 )
  73.                 len = 4;
  74.             BlockMove(argstr,&sig,len);                // Copy signature
  75.             
  76.             // Here we go. Watch carefully:
  77.             
  78.             err = SignatureToApp(sig, &psn, &file, &launched, mode, launchContinue);
  79.             
  80.             if( err==fnfErr ) {
  81.                 fprintf(stderr,"Launch: No application with signature '%.4s' found.\n", &sig);
  82.                 return 1;
  83.             } else if( err==procNotFound ) {
  84.                 fprintf(stderr,"Launch: No application with signature '%.4s' is running.\n", &sig);
  85.                 return 1;
  86.             }else if( err ) {
  87.                 fprintf(stderr,"Launch: Error %d (signature '%.4s').\n", err,&sig);
  88.                 return 1;
  89.             }
  90.             
  91.             if( mode < Sig2App_LaunchApplication ) {
  92.                 printf("'%.4s': PSN= {%d/%d}; File= {vol=%hd, dir=%d, name=%P}\n",
  93.                                 &sig,
  94.                                 psn.highLongOfPSN,psn.lowLongOfPSN,
  95.                                 file.vRefNum, file.parID, file.name);
  96.             }
  97.         }
  98.     }
  99.     
  100.     if( !foundSignature ) {
  101.         fprintf(stderr,"Launch: Missing application signature\n");
  102.         return 1;
  103.     }
  104.     return 0;
  105. }